<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Mypdo
 *
 * @author mateusz.ledzewicz
 */
class Mypdo extends PDO{
    //put your code here
    protected static $pdo = null;
    public static $counter = 0;
   
    public function __construct($host, $username, $passwd, $dbname, $options=array())
	{
        self::$counter++;
		$dsn  =	'mysql:dbname='.$dbname.';host='.$host;
		parent::__construct($dsn, $username, $passwd, $options);
	}
    
    public static function connect($host, $username, $password, $dbname, $options=array())
	{
		try{
			if(is_null(self::$pdo)) self::$pdo = new Mypdo($host, $username, $password, $dbname, $options);
			return self::$pdo;
		}
		catch(Exception $e){
			var_dump($e);
		}
	}
    
    public static function getInstance()
	{
		return self::$pdo;
	}
}

?>
